﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Truron.Purchase.Model.RemoteModel;
using Truron.Purchase.Utility.RedisHelper;

namespace Truron.Purchase.Api.Utility
{
    public class CrmServiceHelp
    {
        private static string CrmApiUrl = "";//系统服务调用地址
        public readonly static CrmServiceHelp Instance = new CrmServiceHelp();
        public CrmServiceHelp()
        {
            var Configuration = new ConfigurationBuilder()
                  .SetBasePath(Directory.GetCurrentDirectory())
                  .AddJsonFile("appsettings.json", optional: true)
                  .Build();
            CrmApiUrl = Configuration.GetSection("AppSettings:CrmApiUrl").Value;

        }
        public (int code, List<CrmEntrustModel> list)  GetEntrustsByNotice(UserCache userToken, List<int> noticeIds)
        {
            Dictionary<string, object> postData = new Dictionary<string, object>();
            postData.Add("noticeIds", noticeIds);
            var EntrustListObj = ApiHelp.WebPost(CrmApiUrl + "CrmOrder/RemoteGetEntrustsByNotice", userToken.UserToken, postData);
            if (EntrustListObj.code > 0)
                return (EntrustListObj.code, null);
            return (EntrustListObj.code, JsonConvert.DeserializeObject<List<CrmEntrustModel>>(EntrustListObj.data.ToString()));
        }


    }
}
